function Drag() {
    function bind(elm, binding) {
        elm.style.cursor = 'grab'
        elm.addEventListener('mousedown', ev => {
            var $tar = elm;
            $tar.style.cursor = "grabbing"
            var oDiv = $tar;
            var disX = 0;
            var disY = 0;
            var oDivLeft = 0;
            var oDivTop = 0;
            var pdisX = 0;
            var pdisY = 0;
            var oEvent = ev;
            var par = oDiv.parentNode;
            disX = oEvent.clientX;
            disY = oEvent.clientY;
            pdisX = par.offsetLeft;
            pdisY = par.offsetTop;
            var minLeft = 100 - par.clientWidth;
            if (oDiv.setCaptrue) {
                oDiv.onmousemove = mouseMove;
                oDiv.onmouseup = mouseUp;
                oDiv.setCaptrue()
            } else {
                document.onmousemove = mouseMove;
                document.onmouseup = mouseUp;
            };

            function mouseMove (ev){
                var oEvent = ev || event;
                oDivLeft = oEvent.clientX - disX;
                oDivTop = oEvent.clientY - disY;
                par.style.marginLeft = 0;
                
                var left = pdisX + oDivLeft;
                var top = pdisY + oDivTop;
                top = top < 0 ? 0 : top;
                left = left < minLeft ? minLeft : left;
                par.style.left = left + 'px';
                par.style.top = top + 'px';
                par.style.marginTop = 0;
            }

            function mouseUp (ev) {
                var oEvent = ev || event;
                $tar.style.cursor = 'grab'
                this.onmousemove = null;
                this.onmouseup = null;
                if (oDiv.releaseCapture) {
                    oDiv.releaseCapture()
                }
            }
            return false;
        });
    }
    function unbind(elm) {
        elm.removeEventListener('mousedown');
    }
    return {
        bind,
        unbind
    }
}
export default Drag();